﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace DARE
{
    public class CComboBoxData : CWidgetData
    {
        public int count;
        public string defaultSelected;
        public Color hlColor;
        public CListBoxData list;
        public int maxDisplayed;
        public float maxWidth;
        public string selected;

        public override void FillDataStructure(CWidget wid)
        {
            CComboBox w = wid as CComboBox;
            base.FillDataStructure(wid);
            count = w.Count;
            if (w.Selected != null)
                defaultSelected = w.Selected.Name;
            hlColor = w.HLColor;
            list = new CListBoxData();
            list.FillDataStructure(w.List);
            maxDisplayed = w.MaxDisplayed;
            maxWidth = w.MaxWidth;
            if (w.Selected != null)
                selected = w.Selected.Name;
        }

        public override void FillFromDataStructure(ref CWidget wid, CHUDSystem hud)
        {
            base.FillFromDataStructure(ref wid, hud);
            (wid as CComboBox).Selected = hud.GetElement(defaultSelected);
            if ((wid as CComboBox).Selected != null && !isVisible)
                (wid as CComboBox).Selected.Hide();
            (wid as CComboBox).HLColor = hlColor;
            (wid as CComboBox).List = hud.GetElement(list.name) as CListBox;
            if (!isVisible)
                (wid as CComboBox).List.Hide();
            if (hud.Widgets.ContainsKey((wid as CComboBox).List.Name))
                hud.Widgets[(wid as CComboBox).List.Name] = (wid as CComboBox).List;//// LE PROBLEME A L'AIR DE VENIR D'ICI!!!!!!!!!!!!!!!!
            (wid as CComboBox).MaxDisplayed = maxDisplayed;
            (wid as CComboBox).MaxWidth = maxWidth;
            (wid as CComboBox).Selected = hud.GetElement(selected);
            if ((wid as CComboBox).Selected != null && !isVisible)
                (wid as CComboBox).Selected.Hide();
            (wid as CComboBox).List.Actualize();
        }
    }
}
